package cn.ycgogo.org.controller;

import cn.ycgogo.org.service.ShopAuditLogService;
import cn.ycgogo.org.domain.ShopAuditLog;
import cn.ycgogo.org.query.ShopAuditLogQuery;
import cn.ycgogo.org.util.AjaxResult;
import cn.ycgogo.org.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后端接口类；
 * @author L1vezZ
 */
@RestController
@RequestMapping("/shopAuditLog" )
public class ShopAuditLogController {

    /**
     * The Shop audit log service.
     */
    @Autowired
    public ShopAuditLogService shopAuditLogService;

    /**
     * 接口：添加或修改
     *
     * @param shopAuditLog 传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody ShopAuditLog shopAuditLog) {
        try {
            if (shopAuditLog.getId() != null) {
                shopAuditLogService.update(shopAuditLog);
            } else {
                shopAuditLogService.save(shopAuditLog);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("操作失败", false);
        }
    }

    /**
     * 接口：删除
     *
     * @param id the id
     * @return AjaxResult 响应给前端
     */
    @DeleteMapping(value = "/{id}" )
    public AjaxResult delete(@PathVariable("id" ) Long id) {
        try {
            shopAuditLogService.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult("操作失败", false);
        }
    }

    /**
     * 接口：批量删除
     *
     * @param ids the ids
     * @return AjaxResult 响应给前端
     */
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids) {
        try {
            shopAuditLogService.patchDelete(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult( "批量删除失败",false );
        }
    }

    /**
     * 接口：查询单个对象
     *
     * @param id the id
     * @return the shop audit log
     */
    @GetMapping("/{id}" )
    public ShopAuditLog findOne(@PathVariable("id" ) Long id) {
        return shopAuditLogService.loadById(id);
    }


    /**
     * 接口：查询所有
     *
     * @return list
     */
    @GetMapping
    public List<ShopAuditLog> findAll() {
        return shopAuditLogService.loadAll();
    }


    /**
     * 接口：分页查询或高级查询
     *
     * @param query 查询对象
     * @return PageList 分页对象
     */
    @PostMapping
    public PageList<ShopAuditLog> queryPage(@RequestBody ShopAuditLogQuery query) {
        return shopAuditLogService.queryPage(query);
    }
}
